package ar.com.sectorwine.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import ar.com.sectorwine.entities.Stock;

public interface StockRepository extends JpaRepository<Stock, Long> {

	List<Stock> findAllByAlcohol(String alcohol);

	@Query(value = "SELECT s.* FROM stock s INNER JOIN empresa_stock es ON s.id = es.productos_id INNER JOIN empresa e ON es.empresa_id = e.id WHERE s.baja = false AND e.id = :idEmpresa", nativeQuery = true)
	List<Stock> listarStockDeAlta(@Param("idEmpresa") Long idEmpresa);

	@Query(value = "SELECT count(ints.id) FROM stock s INNER JOIN stock_interesstock sis ON s.id = sis.stock_id INNER JOIN interesstock ints ON ints.id = sis.interesados_id WHERE s.variedad = :var AND  s.fechacreacionstock >= :desde AND  s.fechacreacionstock <= :hasta", nativeQuery = true)
	java.math.BigInteger buscarNumInteresados(@Param ("desde")  Date desdeNew, @Param ("hasta")  Date hastaNew, @Param ("var") String variedad);

}
